import org.jibble.pircbot.PircBot;

public class TikoBot extends PircBot {
	private String[] strtaulu;

	public TikoBot() {
		this.setName("TikoBot");
	}

	public void onMessage(String channel, String sender, String login,
			String hostname, String message) {
		if (message.equalsIgnoreCase("!aika")) {
			String time = new java.util.Date().toString();
			sendMessage(channel, sender + ": Aika on " + time);
		}

		
		if (message.equalsIgnoreCase("!safka ma")) {

			try {
				strtaulu = WebsiteReader.palauta("maanantai").split("\n");
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			for (int i = 0; i < strtaulu.length; i++) {
				sendMessage(channel, " " + strtaulu[i]);
			}

		}
		if (message.equalsIgnoreCase("!safka ti")) {

			try {
				strtaulu = WebsiteReader.palauta("tiistai").split("\n");
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			for (int i = 0; i < strtaulu.length; i++) {
				sendMessage(channel, " " + strtaulu[i]);
			}

		}
		if (message.equalsIgnoreCase("!safka ke")) {

			try {
				strtaulu = WebsiteReader.palauta("keskiviikko").split("\n");
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			for (int i = 0; i < strtaulu.length; i++) {
				sendMessage(channel, " " + strtaulu[i]);
			}

		}
		if (message.equalsIgnoreCase("!safka to")) {

			try {
				strtaulu = WebsiteReader.palauta("torstai").split("\n");
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			for (int i = 0; i < strtaulu.length; i++) {
				sendMessage(channel, " " + strtaulu[i]);
			}

		}
		if (message.equalsIgnoreCase("!safka pe")) {

			try {
				strtaulu = WebsiteReader.palauta("perjantai").split("\n");
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			for (int i = 0; i < strtaulu.length; i++) {
				sendMessage(channel, " " + strtaulu[i]);
			}

		}
		if (message.equalsIgnoreCase("!task")) {

			try {
				strtaulu = WebsiteReader.palautaTasks().split("-");
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			for (int i = 0; i < strtaulu.length; i++) {
				if (strtaulu[i].equals("")) {
					continue;
				} else {
					sendMessage(channel, "" + strtaulu[i]);
				}

			}
		}
	}
}
